/*
 * HackSQL
 * Copyright (C) 2008-2009
 *
 * Authors: Felipe Nascimento Silva Pena
 *          Gustavo Menezes Oliveira
 *          Henrique Montenegro Decaria
 *          Higor Eurípedes Pimentel Fernandes de Araújo
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __UTILS_H__
#define __UTILS_H__

#include <stdarg.h>

/*
 * Checks if 'e' exists, if not set 'v' to 'd'
 */
#define hs_getenv(v, e, d) \
	v = getenv(e); \
	if (!v || !*v) { \
		v = d; \
	}
#define hs_check_alloc(v) \
	if (!v) { \
		hs_error(HS_ERROR_ALLOC_ERROR, "Could not alloc memory for %s. Aborting.", "##v##"); \
		exit(1); \
	}

#define hs_return_if_null(v) if (v == NULL) return;

inline void *get_in_addr(struct sockaddr *sa);

/*
 * Some string functions
 */
char *trimstr(char *string);
char **tokenize(char *str, char *delimiters, int *num);
void hs_error(hs_errno_t errno, char *format, ...);
void hs_warning(char *format, ...);
char *getfilecontents(char *filename);
long int getfilesize(char *filename);

#endif				/* __UTILS_H__ */
